//
//  GTChannelViewCell.m
//  GiftTalk
//
//  Created by Wan on 16/3/23.
//  Copyright © 2016年 Wan. All rights reserved.
//

#import "GTChannelViewCell.h"
#import "GTGiftItem.h"
#import <UIImageView+WebCache.h>
#import "UIImageView+Extension.h"

@interface GTChannelViewCell()

@property (weak, nonatomic) IBOutlet UIImageView *coverImageView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *likeCount;

@property (weak, nonatomic) IBOutlet UIButton *likeButton;
@end

@implementation GTChannelViewCell

- (void)awakeFromNib {
    // Initialization code
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self setupLabelShadow];
}

/**
 *  遮罩阴影
 */
- (void)setupLabelShadow
{
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors = @[(id)[UIColor clearColor].CGColor, (id)[UIColor blackColor].CGColor];
    gradientLayer.opacity  = 0.6;
//    gradientLayer.frame = CGRectMake(0, 0, GTScreenW - 8 * 2, self.titleLabel.superview.gp_height);
    gradientLayer.frame = CGRectMake(0, self.titleLabel.y - 20, GTScreenW - 8 * 2 , self.titleLabel.height + 5);
    [self.titleLabel.superview.layer insertSublayer:gradientLayer below:self.titleLabel.layer];
}

- (IBAction)likeButton:(UIButton *)sender {
    GTLogFunc
}

- (void)setItem:(GTGiftItem *)item
{
    self.titleLabel.text = item.title;
    
    [self.coverImageView setImage:item.cover_image_url placeHolder:@"app_logo"];
    
#warning 设置喜欢按钮
    [self.likeCount setText:[NSString stringWithFormat:@"%ld",item.likes_count]];
}


// 重写 Setframe 方法,用于调整cell 上下左右间距
- (void)setFrame:(CGRect)frame
{
    CGFloat margin = 8;
    
    frame.origin.x = margin;
    frame.origin.y += margin;
    frame.size.width -= margin * 2;
    frame.size.height -= margin;
    
    [super setFrame:frame];
}
@end
